<template>
	<view class="page content">
		<TopHead :title="'修改密码'"></TopHead>
		<view class="contBox">

			<view class="iteminput">
				<text class="">用户名</text>
			<!-- 	<input class="uni-input ipt" type="text"  disabled v-model="name" placeholder="用户名" /> -->
			{{userInfo.userName}}
			</view>
			<view class="iteminput">
				<text>旧密码</text>
				<input class="uni-input ipt" type="text" v-model="form.oldPassword" placeholder="请输入旧密码" />
			</view>
			<view class="iteminput">
				<text>新密码</text>
				<input class="uni-input ipt" type="text" v-model="form.newPassword" placeholder="请输入新密码" />
			</view><view class="iteminput">
				<text>新密码</text>
				<input class="uni-input ipt" type="text" v-model="form.newPassword2" placeholder="请输入新密码" />
			</view>
			
			<view class="submitBtn" @click="bindSubmit">确认修改</view>
		</view>
	</view>
</template>

<script>
	import TopHead from '../../components/topHead/topHead.vue';
	export default {
		components: {
			TopHead
		},
		data() {
			return {

				list: [], // 列表
				page: 1,
				pageSize: 20, // 
				total: 0, // 总数
				hotList: [], // 热销
				headImage: '', // 头像
				selectedAddress: [], // 用于存储用户选择的省市区信息
				address: '', // 地址显示
				phone: '', // 电话
				name: '', // 名字
				address2: '',
				isChecked: false, // 是否选中
				
				userInfo:{},
				form:{}

			}
		},
		onLoad(options) {
			console.log(options)
			this.init()
		},
		onShow() {
			this.page = 1
			this.total = 0
			this.list = []
			// this.initData()
			this.userInfo =	JSON.parse(uni.getStorageSync('user_info'));
			console.log("userInfo",this.userInfo );
		},
		onReachBottom() {
			// 触底分页
			console.log('触底')
			if (this.total > this.list.length) {
				this.page = parseInt(this.page) + 1
			}
		},
		methods: {
			
			
			
			// 提交
			bindSubmit() {
				var parms=this.form;
				if(parms.oldPassword==undefined){
					uni.showToast({
						title: '请输入原密码',
						icon: 'none'
					})
					return;
				}
				if(parms.newPassword==undefined){
					uni.showToast({
						title: '请输入新密码',
						icon: 'none'
					})
					return;
				}
				if(parms.newPassword!=parms.newPassword2){
					uni.showToast({
						title: '两次输入新密码不一致',
						icon: 'none'
					})
					return;
				}
				
				let data = {
				 	oldPassWord: parms.oldPassword,
					newPassWord: parms.newPassword,
				 				}
								
								this.$http.fetchData({
									url: '/wechatApplet/worker/user/'+this.userInfo.id+"/password/modify",
									method: 'PUt',
									data: data,
									success(res) {
										if(res.code!=200){
											uni.showToast({
												title: res.msg,
												icon: 'none'
											});
											return;
										}
										 
										 uni.showToast({
										 	title: "密码修改成功！",
										 	icon: 'none'
										 });
									}
								})
				 
			},
			init() {
				let selectedAddress = '重庆市-县-丰都县'
				selectedAddress = selectedAddress.split('-')
				this.selectedAddress = selectedAddress
				console.log(this.selectedAddress)
				if (this.selectedAddress) {
					this.address = selectedAddress[0] + '-' + selectedAddress[1] + '-' + selectedAddress[2]
				}

			},
			//  选择的省市区
			onRegionChange(event) {
				this.selectedAddress = event.detail.value;
				console.log('选择的省市区', this.selectedAddress);
				let selectedAddress = this.selectedAddress
				this.address = selectedAddress[0] + '-' + selectedAddress[1] + '-' + selectedAddress[2]
				console.log(this.address)
				// event.detail.value 是一个包含三个元素的数组，分别是省份、城市和区县
				// 例如：["广东省", "广州市", "天河区"]
			},
			// 是否默认
			switchChange(event) {
				console.log(event.detail.value)
				this.isChecked = event.detail.value
			},
			onChooseAvatar(e) {
				this.headImage = e.detail.avatarUrl
				console.log(e.detail.avatarUrl)
				let file = e.detail.avatarUrl
				let _that = this

				uni.uploadFile({
					url: _that.$http.baseUrl + 'updata', //附件上传的服务器接口地址，非真实的接口地址
					filePath: file, //要上传文件资源的路径,不同的组件
					name: 'file', //文件对应的 key , 开发者在服务器端通过这个 key 可以获取到文件二进制内容,即附件信息的接收字段名称
					formData: { //HTTP 请求中其他额外的 form data	

					},
					success: (res) => { //回调方法
						console.log(JSON.parse(res.data));
						let data = JSON.parse(res.data);

						console.log(data.data.url)
						_that.headImage(data.data.url)
						// that.listFiles.push(data.url);


					}
				});
			},
			// 数据请求示例
			initData() {
				let _this = this;
				_this.$http.fetchData({
					url: '/api/biaoduan',
					method: 'GET',
					data: {},
					success(res) {
						// uni.showToast({
						// 	title: res.message,
						// 	icon: 'none'
						// });
						_this.list = [..._this.list, ...res.data]
						this.total = res.total
						let listData = res.data
						if (res.total == 1) {
							let id = listData[0].id
							let total = this.total
							let paramsStr = `?biaoduan_id=${id}&biaoduanTotal=${total}`
							uni.redirectTo({
								url: `/pages/procedureList/procedureList${paramsStr}`
							})
						}
					}
				})
			},
			// 查看详情
			announcementDetails(item) {
				console.log(item.id)
				let id = item.id
				let paramsStr = `?id=${id}`
				uni.navigateTo({
					url: `/pages/index/announcementDetails${paramsStr}`
				})
			},

		}
	}
</script>

<style scoped>
	.content {
		background: rgba(62, 122, 233, 0.05);
		padding-bottom: 60rpx;
		height: 100%;
		box-sizing: border-box;
		overflow-y: auto;
	}

	.contBox {
		padding: 30rpx;
		padding-top: 196rpx;
	}

	.title1 {
		font-size: 32rpx;
		font-family: Microsoft YaHei, Microsoft YaHei-Bold;
		font-weight: 700;
		text-align: center;
		color: #5d4529;
	}

	.time {
		font-size: 24rpx;
		font-family: Microsoft YaHei, Microsoft YaHei-Regular;
		font-weight: 400;
		text-align: center;
		color: #b8c5d3;
		margin-top: 30rpx;

	}

	.details {
		margin-top: 30rpx;
		font-size: 28rpx;
		font-family: Microsoft YaHei, Microsoft YaHei-Regular;
		font-weight: 400;
		color: #22172a;
	}

	.button-wrapper {
		background: none;
		padding-right: 0;
		margin-top: 60rpx;

	}

	.button-wrapper::after {
		border: none;
	}

	.user-headImg {
		width: 162rpx;
		height: 162rpx;
		background: rgba(0, 0, 0, 0.00);
		border-radius: 50%;
	}

	.iteminput {
		position: relative;
		padding-left: 206rpx;
		line-height: 131rpx;
		border-bottom: 2rpx solid rgba(94, 94, 94, 0.1);
	}

	.switch {
		text-align: right;
	}

	.iteminput text {
		line-height: 38rpx;
		position: absolute;
		left: 0;
		top: 50%;
		margin-top: -19rpx;
		font-size: 28rpx;
		font-family: Microsoft YaHei, Microsoft YaHei-Bold;
		font-weight: 700;
		color: #5d4529;
	}

	.iteminput .ipt {
		height: 131rpx;

	}

	.iteminput .ipt .picker {
		position: relative;
	}

	.iteminput .ipt .picker .right-icon {
		position: absolute;
		right: 0;
		top: 50%;
		margin-top: -66rpx;
	}

	.iteminput .ipt ::placeholder {
		font-size: 28rpx;
		font-family: Microsoft YaHei, Microsoft YaHei-Regular;
		font-weight: 400;
		color: #c2c2c2;

	}

	.iteminput .text1 {
		letter-spacing: 24rpx;
	}

	.submitBtn {
		font-size: 32rpx;
		font-family: Microsoft YaHei, Microsoft YaHei-Regular;
		font-weight: 400;
		color: #ffffff;
		line-height: 42rpx;
		text-align: center;
		margin: 0 auto;
		width: 590rpx;
		height: 112rpx;
		line-height: 112rpx;
		background: #e47917;
		border-radius: 10rpx;
		margin-top: 242rpx;
	}
</style>